﻿using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CommonEntity.CommonImageEntities;

namespace ScienceAIApp.Views;
/// <summary>
/// Interaction logic for AiToolBarView.xaml
/// </summary>
public partial class AiToolBarView
{
    public AiToolBarView()
    {
        InitializeComponent();
        this.WhenActivated(_activated);
    }

    private void _activated(CompositeDisposable disposable)
    {
        this.OneWayBind(
           ViewModel,
           model => model.WindowMax,
           view => view.SliderRange.Maximum)
           .DisposeWith(disposable);

        this.OneWayBind(
            ViewModel,
            model => model.WindowMin,
            view => view.SliderRange.Minimum)
            .DisposeWith(disposable);

        this.Bind(
            ViewModel,
            model => model.StartValue,
            view => view.SliderRange.StartValue)
            .DisposeWith(disposable);

        this.Bind(
            ViewModel,
            model => model.EndValue,
            view => view.SliderRange.EndValue)
            .DisposeWith(disposable);

        this.OneWayBind(
            ViewModel,
            model => model.SubToolViewModel,
            view=>view.SubToolsViewHost.ViewModel
            ).DisposeWith(disposable);


        #region 工具栏绑定

        this.OneWayBind(
                ViewModel,
                model => model.IsSelectCrossLine,
                view => view.CrossLineBtn.Opacity,
                isSelected => isSelected ? 1 : 0.3)
            .DisposeWith(disposable);

        this.OneWayBind(
                ViewModel,
                model => model.IsSelectDrawLine,
                view => view.BrushBtn.Opacity,
                isSelected => isSelected ? 1 : 0.3)
            .DisposeWith(disposable);

        this.OneWayBind(
                ViewModel,
                model => model.IsSelectEraseLine,
                view => view.EraseBtn.Opacity,
                isSelected => isSelected ? 1 : 0.3)
            .DisposeWith(disposable);

        this.OneWayBind(
                ViewModel,
                model => model.IsSelectMarkLine,
                view => view.PinBtn.Opacity,
                isSelected => isSelected ? 1 : 0.3)
            .DisposeWith(disposable);

        this.BindCommand(
            ViewModel,
            vm => vm.SwitchToolBarCommand,
            v => v.CrossLineBtn,
            Observable.Return(SegToolsEnum.CrossLine),
            nameof(this.CrossLineBtn.MouseDown)
            ).DisposeWith(disposable);

        this.BindCommand(
            ViewModel,
            vm => vm.SwitchToolBarCommand,
            v => v.BrushBtn,
            Observable.Return(SegToolsEnum.DrawNone),
            nameof(this.BrushBtn.MouseDown)
        ).DisposeWith(disposable);

        this.BindCommand(
            ViewModel,
            vm => vm.SwitchToolBarCommand,
            v => v.EraseBtn,
            Observable.Return(SegToolsEnum.Erase),
            nameof(this.EraseBtn.MouseDown)
        ).DisposeWith(disposable);

        this.BindCommand(
            ViewModel,
            vm => vm.SwitchToolBarCommand,
            v => v.PinBtn,
            Observable.Return(SegToolsEnum.MarkNone),
            nameof(this.PinBtn.MouseDown)
        ).DisposeWith(disposable);

        #endregion
    }
}
